package com.example.shopping.service;

import com.example.shopping.entity.Goods;
import com.example.shopping.repository.GoodsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService{
    @Autowired
    private GoodsRepository goodsRepository;

    @Override
    public List<Goods> findAll() {
        return goodsRepository.findAll();
    }

    @Override
    public Goods findByGid(String gid) {
        return goodsRepository.findByGid(gid);
    }

    @Override
    public void updateGood(Goods updatedGood) {
        goodsRepository.save(updatedGood);
    }

    @Override
    public void deleteGoodsByGid(String gid) {
        goodsRepository.deleteById(gid);
    }

    @Override
    public void addGood(Goods good) {
        goodsRepository.save(good);
    }

    @Override
    public Page<Goods> findGoods(String goodsname, String gid, String goodstype, Pageable pageable) {
        return goodsRepository.findGoods(goodsname, gid, goodstype, pageable);
    }
}
